package com.hightrast.service.util;

import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.session.SaSession;
import cn.dev33.satoken.stp.StpUtil;
import com.alibaba.fastjson.JSON;
import com.hightrast.service.api.baseEntity.exception.ServiceException;
import com.hightrast.service.api.entity.RastUser;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class SecureUtil {

    public static RastUser getUser()
    {
        Object longId;
        try {
            longId = StpUtil.getLoginId();
        } catch (NotLoginException e) {
            throw new ServiceException("Exception");

        }
        SaSession session = StpUtil.getSessionByLoginId(longId, true);
        String userStrInfo = session.get("user", new String());
        RastUser user = JSON.parseObject(userStrInfo, RastUser.class);
        return user;
    }
}
